<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:c="">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>Dynamic Table</title>

    <!--dynamic table-->
    <link href="js/advanced-datatable/css/demo_page.css" rel="stylesheet"/>
    <link href="js/advanced-datatable/css/demo_table.css" rel="stylesheet"/>
    <link rel="stylesheet" href="js/data-tables/DT_bootstrap.css"/>

    <link href="css/style.css" rel="stylesheet">
    <link href="css/style-responsive.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->
</head>

<body class="sticky-header">

<section>
    <!-- left side start-->
    <div class="left-side sticky-left-side">

        <!--logo and iconic logo start-->
        <div class="logo">
            <a href="backPage.html"><img src="images/logo.png" alt=""></a>
        </div>

        <div class="logo-icon text-center">
            <a href="backPage.html"><img src="images/logo_icon.png" alt=""></a>
        </div>
        <!--logo and iconic logo end-->

        <div class="left-side-inner">


            <!--sidebar nav start-->
            <ul class="nav nav-pills nav-stacked custom-nav">
                <li class="menu-list nav-active"><a href=""><i class="fa fa-home"></i>
                    <span>用户</span></a>
                    <ul class="sub-menu-list">
                        <li><a href="/back/userList"> 用户列表</a></li>
                        <li><a href="/back/userType"> 用户权限</a></li>
                    </ul>
                </li>

                <li class="menu-list nav-active"><a href=""><i class="fa fa-laptop"></i>
                    <span>商品</span></a>
                    <ul class="sub-menu-list">
                        <li><a href="/back/product"> 商品列表</a></li>
                        <li><a href="/back/addPage"> 新商品</a></li>
                    </ul>
                </li>
                <li class="menu-list nav-active"><a href=""><i class="fa fa-laptop"></i>
                    <span>订单</span></a>
                    <ul class="sub-menu-list">
                        <li><a href="/back/ordersList"> 订单列表</a></li>
                    </ul>
                </li>
            </ul>
            <!--sidebar nav end-->

        </div>
    </div>
    <!-- left side end-->

    <!-- main content start-->
    <div class="main-content">

        <!-- header section start-->
        <div class="header-section">

            <!--toggle button start-->
            <a class="toggle-btn"><i class="fa fa-bars"></i></a>
            <!--toggle button end-->


            <!--notification menu start -->
            <div class="menu-right">
                <ul class="notification-menu">

                    <li>
                        <a href="#" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                            <img th:src="'/images/touxiang/'+${session.user.fileName}" alt=""/>
                            [[${session.user.userName}]]
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu dropdown-menu-usermenu pull-right">
                            <li><a href="/"><i class="fa fa-sign-out"></i> Log Out</a></li>
                        </ul>
                    </li>

                </ul>
            </div>
            <!--notification menu end -->

        </div>
        <!-- header section end-->




        <!--body wrapper start-->
        <div class="wrapper">
            <div class="row">
                <div class="col-sm-12">

                    <!--高级查询的页面-->
                    <div class="search">
                        <form action="/back/product" method="post" class="form-inline" style="margin-bottom: 10px">
                            商品名称:<input type="text" name="name" class="form-control">
                            <div class="form-group">
                                <label for="exampleInputStockCategoryleveloneId">商品类型:</label>
                                <select id="exampleInputStockCategoryleveloneId" class="form-control"
                                        name="categorylevelone_id">
                                    <option value="">全部</option>
                                    <option value="548">化妆品</option>
                                    <option value="628">家用商品</option>
                                    <option value="660">进口食品</option>
                                    <option value="670">电子商品</option>
                                    <option value="676">保健食品</option>
                                    <option value="681">箱包</option>
                                </select>
                            </div>
                            <input type="submit" value="搜索" class="s_btn">
                        </form>
                    </div>

                    <section class="panel">
                        <header class="panel-heading">
                            商品列表
                            <a href="/back/addPage"
                               style="float: right;font-size: 15px;margin-right: 30px; text-decoration: none;">新增</a>
                        </header>
                        <div class="panel-body">
                            <div class="adv-table">
                                <table class="display table table-bordered table-striped" id="dynamic-table">
                                    <thead>
                                    <tr>
                                        <th class="text-center">商品编号</th>
                                        <th class="text-center">商品名称</th>
                                        <th class="text-center">商品图片</th>
                                        <th class="text-center">商品单价</th>
                                        <th class="text-center">商品积分</th>
                                        <th class="text-center">商品库存</th>
                                        <th class="text-center">类别编号</th>
                                        <th class="text-center">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr class="gradeX" th:each="product:${page.records}">
                                        <td style="text-align: center" class="productId" th:text="${product.id}"></td>
                                        <td class="text-center" th:text="${product.name}"></td>
                                        <td class="text-center"><img th:src="'/images/'+${product.fileName}"
                                                 style="width: 50px;height: 50px;"/>
                                        </td>
                                        <td class="text-center" th:text="${product.price}"></td>
                                        <td class="text-center" th:text="${product.integral}">
                                        <td class="text-center" th:text="${product.stock}"></td>
                                        <td class="text-center" th:text="${product.categoryleveloneId}">4</td>
                                        <td class="text-center">
                                            <a th:href="'/back/updateProduct?productId='+${product.id}+'&pn='+${pn}"
                                               class="update">修改</a>|
                                            <a href="javascript:void(0)" onclick="deleteProduct(this)"
                                               class="delete">删除</a>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                                <div class="row-fluid">
                                    <div class="span6">
                                        <div class="dataTables_info" id="dynamic-table_info">
                                            <input class="pn" type="hidden" th:value="${pn}">
                                            当前第[[${page.current}]]页，总计[[${page.pages}]]页，共[[${page.total}]]条记录。
                                        </div>
                                    </div>
                                    <div class="span6">
                                        <div class="dataTables_paginate paging_bootstrap pagination">
                                            <ul>
                                                <li class="prev"><a th:href="@{/back/product(pn=1)}">← 第一页</a>
                                                </li>
                                                <li th:each="num:${#numbers.sequence(1,page.pages)}"
                                                    th:class="${num == page.current ? 'active':''}">
                                                    <a th:href="@{/back/product(pn=${num})}">[[${num}]]</a>
                                                </li>
                                                <li class="next"><a th:href="@{/back/product(pn=${page.pages})}">最后页
                                                    → </a>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </div>
        <!--body wrapper end-->
    </div>
    <!-- main content end-->
</section>

<!-- Placed js at the end of the document so the pages load faster -->
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery-ui-1.9.2.custom.min.js"></script>
<script src="js/jquery-migrate-1.2.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/modernizr.min.js"></script>
<script src="js/jquery.nicescroll.js"></script>

<!--dynamic table-->
<script type="text/javascript" language="javascript" src="js/advanced-datatable/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/data-tables/DT_bootstrap.js"></script>

<!--common scripts for all pages-->
<script src="js/scripts.js"></script>
<script type="text/javascript">
    function deleteProduct(obj) {
        let index = $(".delete").index(obj);
        let productId = $(".productId").eq(index).text();
        let pn = $(".pn").val();
        if (confirm("是否确定要删除？")) {
            window.location.href = "/back/deleteProductById/" + productId + "/" + pn;
        }
    }
</script>

</body>
</html>
